home *** CD-ROM | disk | FTP | other *** search
- /*
- Blasto
- A small program that blasts an 8 bit color icon to the screen.
- 3-6-92 By Brigham Stevens
- Apple Developer Technical Support
- 3-13-92 - BRS - Uh Oh, it's Friday the 13th
- Cleaned up & commented code here and there.
- 4-13-92 - BRS - changed icon to be self-erasing
- Made code somewhat better by changing names and stuff.
- Added comments
- 4-24-92 - BRS - Added ifdefs around timing code, changed names again.
- 11-11-92 - BRS - made a THINK C project file, and made this code work with
- THINK C. Also changed the date in the comment above.
- */
-
- #ifndef THINK_C
- #include <OSUtils.h>
- #include <Windows.h>
- #include <QDOffscreen.h>
- #include <Retrace.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <Events.h>
- #include <Menus.h>
- #endif
-
- #include "DirectScreen.h"
-
- void InitToolBox(short numMoreMasters);
-
- /* Amount to move icons these need to be around 1 or 2 */
- /* or our icon will not be self erasing */
- #define ROW_OFF 1
- #define COL_OFF 1
-
- #define MAX_SECONDS 100
-
- #ifndef THINK_C
- void ShowResult(long frameCount);
- long AverageTable(long *tab, short count);
- #endif
-
- void main()
- {
- WindowPtr directWindow;
- GrafPort killMenuBar;
- Rect screenRect;
- GDHandle mainScreen;
- PixMapHandle mainscreenPixMap;
- Handle colorIconHandle;
- Point plotLocation;
- short vDelta = ROW_OFF;
- short hDelta = COL_OFF;
- long frameCount;
- long *ticks = (long*)0x16A;
- long beforeTicks;
- long tickTable[MAX_SECONDS];
- short tickIndex = 0;
-
- /* Standard Witch Chant enclosed... */
- InitToolBox(4); /* 4 calls to MoreMasters */
-
- /* get a handle to the color icon we are drawing */
- colorIconHandle = GetResource('icl8',128);
- if(!colorIconHandle) {
- SysBeep(5);
- DebugStr("\pBuild problems: 'icl8' not loaded.");
- return;
- }
-
- /* cover up the part of the screen we are writing on */
- /* with a window, so other apps will not mess with our */
- /* animation via update events in the background */
- screenRect = qd.screenBits.bounds;
- directWindow = NewWindow(nil,&screenRect,nil,true,plainDBox,nil,false,0L);
-
- /* This covers up the menu bar */
- /* and fills the screen with white */
- OpenPort((GrafPtr)&killMenuBar);
- EraseRect(&killMenuBar.portRect);
-
- /* get the main screen's Pix map */
- /* Which this program expects to be 8 bits deep */
- mainScreen = GetMainDevice();
- mainscreenPixMap = (**mainScreen).gdPMap;
-
- /* Set up a safe rectangle for bouncing off the screen */
- screenRect.top = 4;
- screenRect.left = 4;
- screenRect.bottom -= 32;
- screenRect.right -= 32;
-
-
- /* loop until the mouse is clicked */
- /* drawing and moving the color icon */
-
-
- for(tickIndex = 0; tickIndex < MAX_SECONDS; tickIndex++) {
- /* This is where to start drawing the color icon*/
- plotLocation.h = 100;
- plotLocation.v = 100;
- frameCount = 0;
- beforeTicks = *ticks;
- while((*ticks - beforeTicks) < 60) {
-
- /* update the location of the icon */
- plotLocation.v += vDelta;
- plotLocation.h += hDelta;
- /* This forces us to stay on the screen and prevent bus errors */
- if(!PtInRect(plotLocation,&screenRect)) {
- vDelta = -vDelta; /* swap the deltas to bounce of corner */
- hDelta = -hDelta;
- }
-
- /* draw the icon */
-
- DirectPlotColorIcon((long *)*colorIconHandle,
- mainscreenPixMap, plotLocation.v, plotLocation.h);
- frameCount++;
- /* this was not part of the timing code, but */
- /* I want to be able to bail out early */
- if(Button()) ExitToShell();
- }
- tickTable[tickIndex] = frameCount;
- }
-
- /* show the average number of frames per second for MAX_SECONDS seconds */
- #ifndef THINK_C
- ShowResult( AverageTable(tickTable,MAX_SECONDS) );
- #endif
-
- CloseWindow(directWindow);
- ClosePort((GrafPtr)&killMenuBar);
- DrawMenuBar();
-
- }